package com.lhh.company.website.admin;

import com.lhh.company.website.entity.Res;
import com.lhh.company.website.service.SysFileService;
import com.lhh.company.website.utils.ExcelUtils;
import jakarta.annotation.Resource;
import lombok.extern.log4j.Log4j2;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;


import java.io.File;
import java.io.IOException;

@Log4j2
@RestController
public class GoodsApi {

    @Value("${filepath}")
    String filepath;

    @Value("${server.domain}")
    String domain;

    @Resource
    SysFileService sysFileService;

    @RequestMapping("/goods/detail")
    @Transactional(rollbackFor = Exception.class)
    public Res detail(MultipartFile file, String fileName) throws IOException {

        return Res.succ();

    }

    @RequestMapping("/goods/sava")
    public Res sava(String id) {

        return Res.succ();
    }


    @RequestMapping("/goods/delete")
    public Res delete(String id) {

        return Res.succ();
    }

    @RequestMapping("/goods/fileToParam")
    public Res fileToParam(@Param("id") String id,@Param("fileType") String fileType) throws Exception {
        String filetmpPath = filepath+ "tmp/"+id+"."+fileType;
        File file = new File(filetmpPath);
        return Res.succ(ExcelUtils.read(file));
    }
}
